package demo14

// 状态设计模式
// state
// 一个状态接替另一个状态
// 比如一周有7天 7天交替循环
 
import "fmt"

type Week interface{
	Today() // 当天信息
	Next(*DayContext) // 下一天信息
}

type DayContext struct{
	today Week // 当前的信息内容
}

func NewDayConext() *DayContext{
	return &DayContext{
		today:&Sunday{},
	}
}

func (d *DayContext) Today(){
	d.today.Today()
}

func (d *DayContext)Next(){
	d.today.Next(d)
}

type Sunday struct{}

func (s *Sunday)Today(){
	fmt.Println("Sunday")
}
func (s *Sunday)Next(ctx *DayContext){
	ctx.today = &Monday{}
}

type Monday struct{}

func (m *Monday)Today(){
	fmt.Println("Monday")
}
func (m *Monday)Next(ctx *DayContext){
	ctx.today = &Tuesday{}
}
type Tuesday struct{}

func (*Tuesday) Today() {
    fmt.Printf("Tuesday\n")
}

func (*Tuesday) Next(ctx *DayContext) {
    ctx.today = &Wednesday{}
}
type Wednesday struct{}
func (w *Wednesday)Today(){
	fmt.Println("Wednesday")
}
func (w *Wednesday)Next(ctx *DayContext){
	ctx.today = &Thursday{}
}

type Thursday struct{}
func (t *Thursday)Today(){
	fmt.Println("Thursday")
}
func (t *Thursday)Next(ctx *DayContext){
	ctx.today = &Friday{}
}

type Friday struct{}
func (f *Friday)Today(){
	fmt.Println("Friday")
}
func (f *Friday)Next(ctx *DayContext){
	ctx.today = &Saturday{}
}

type Saturday struct{}
func (*Saturday) Today(){
	fmt.Println("Saturday")
}
func (*Saturday) Next(ctx *DayContext){
	ctx.today = &Sunday{}
}